export function login({ name, password }) {
  return $request({
    url: '/v1/api/admin/login',
    method: 'POST',
    data: {
      name,
      password
    }
  })
}

export function register({ name, password, key }) {
  return $request({
    url: '/v1/api/admin/register',
    method: 'post',
    data: {
      name,
      password,
      key
    }
  })
}

export function getUserInfo() {
  return $request({
    url: '/v1/api/admin/info',
    method: 'get',
    needAuth: true
  })
}

export function getEnumerator() {
  return $request({
    url: '/v1/api/constants',
    method: 'get'
  })
}

export function getMovieList({ keyword, start = 0, limit = 20, genre = "0", region = "0", pubYear = "" }) {
  return $request({
    url: '/v1/api/movie/list/search',
    method: 'get',
    params: {
      q: keyword,
      start,
      limit,
      genre,
      region,
      pub_years: pubYear
    }
  })
}

export function deleteMovies(ids) {
  return $request({
    url: '/v1/api/movie/delete',
    method: 'POST',
    data: {
      ids: Array.isArray(ids) ? ids : [ids]
    },
    needAuth: true
  })
}

export function getMovie(id) {
  return $request({
    url: '/v1/api/movie',
    params: {
      id,
    }
  })
}

export function upload(formData) {
  return $request({
    url: '/v1/api/upload',
    method: 'POST',
    data: formData,
    needAuth: true
  })
}

export function updateMovie(data) {
  return $request({
    url: '/v1/api/movie/update',
    method: 'PUT',
    data,
    needAuth: true
  })
}

export function createMovie(data) {
  return $request({
    url: '/v1/api/movie/create',
    method: 'POST',
    data,
    needAuth: true
  })
}

export function getReviewList({start = 0, limit = 20, id}) {
  return $request({
    url: '/v1/api/movie/review/list',
    method: 'get',
    params: {
      id,
      start,
      limit,
      sort: "created_at"
    }
  })
}

export function deleteReviews(ids) {
  return $request({
    url: '/v1/api/movie/review/delete',
    method: 'POST',
    data: {
      ids: Array.isArray(ids) ? ids : [ids]
    },
    needAuth: true
  })
}

export function updateReview(data) {
  return $request({
    url: '/v1/api/movie/review/update',
    method: 'PUT',
    data,
    needAuth: true
  })
}

export function createReview(data) {
  return $request({
    url: '/v1/api/movie/review/create',
    method: 'POST',
    data,
    needAuth: true
  })
}

export function getReviewDetail(id) {
  return $request({
    url: '/v1/api/movie/review',
    method: 'GET',
    params: {
      id,
    },
  })
}